﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Smo;
using System.Data.SqlClient;

namespace test
{
    public static class helper
    {
        public static bool CDCEnabled(this Database d)
        {
            using (SqlDataReader sr = d.Parent.ConnectionContext.ExecuteReader(@"
                select name,is_cdc_enabled from sys.databases
                where [name] = " + FormatSQL(d.Name)))
            {
                while (sr.Read())
                {
                    return (bool.Parse( sr["is_cdc_enabled"].ToString()));
                }
                return false;
            }
        }

        private static string FormatSQL(string p)
        {
            return "'" + p.Replace("'","''") + "'";
        }
    }
}
